package com.ndp.fb.mq;

import org.springframework.context.ApplicationContext;

import com.alibaba.dubbo.container.Main;
import com.ndp.ec.core.api.DPARobotCoreService;
import com.ndp.fb.config.BaseConfig;
import com.ndp.fb.config.XmlBaseConfig;
import com.ndp.fb.dubbo.container.ContainerPost;
import com.ndp.fb.dubbo.container.SpringBootContainer;
import com.ndp.fb.exception.CheckedException;
import com.ndp.fb.mq.api.service.schedulerservice.HttprequestSchedulerService;
import com.ndp.fb.util.ThreadPool;

/**
 * Created by hunk.qin on 2015/2/3.
 */
public class RunMain {

    public static void main(String[] args) {
        BaseConfig.DEV = true;
        XmlBaseConfig.LoadXmlConfig = false;

        SpringBootContainer.containerPostList.add(new ContainerPost() {
            @Override
            public void doPost(ApplicationContext applicationContext) {
                request(applicationContext);
                DPARobotCoreService dpaRobotCoreService = applicationContext.getBean(DPARobotCoreService.class);
            	try {
//            		dpaRobotCoreService.createMarketingTarget("90ea87ed-55d0-4127-8591-4ae905396908");
					dpaRobotCoreService.optimizeMarketingTarget("42ee4e3d-6109-4f7f-81c5-c35d96eceb7f",true);
				} catch (CheckedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
//                AdPublishSchedulerService adPublishSchedulerService = applicationContext.getBean(AdPublishSchedulerService.class);
//                adPublishSchedulerService.autoPublishForThirdpic();
//                adPublishSchedulerService.autoAuditAd();
//                AdImageSchedulerService adImageSchedulerService = applicationContext.getBean(AdImageSchedulerService.class);
//                adImageSchedulerService.perfectCreativeImageHash();
//                SyncBusinessDataToMongoService syncBusinessDataToMongoService = applicationContext.getBean(SyncBusinessDataToMongoService.class);
//                syncBusinessDataToMongoService.fillAdGroupAndAdSet();
//                AdResourceSchedulerService adResourceSchedulerService = applicationContext.getBean(AdResourceSchedulerService.class);
//                adResourceSchedulerService.getImageHash("");
            }
        });
        String[] argsparams = {"springboot"};
        Main.main(argsparams);
        System.out.print("start  down");
    }

    private static void request(ApplicationContext applicationContext) {
        ThreadPool.execute(new Runnable() {
            @Override
            public void run() {
//                while (true) {
//                    HttprequestSchedulerService httprequestSchedulerService = applicationContext.getBean(HttprequestSchedulerService.class);
//                    httprequestSchedulerService.requestConsumer();
//                    try {
//                        Thread.sleep(2000);
//                        System.out.println("--------------------------------aaaaaaaaaaaaa----------------------");
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
            }
        });
    }
}
